package com.sky.controller.user;

import com.sky.constant.ShopStatusConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @author bairimengchang
 * @version 1.0
 * @project sky-take-out
 * @description C端店铺操作控制器
 * @date 2024/08/14 15:22:39
 */
@RestController("UserShopController")       //这里因为默认是单例bean，所以重命名一下，也可以修改类名
@RequestMapping("/user/shop")
@Slf4j
@Api(tags = "C端店铺操作接口")
public class ShopController {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    /**
     * 获取营业状态
     * @return 营业状态结果对象
     */
    @ApiOperation("获取营业状态")
    @GetMapping("/status")
    public Result<Integer> getStatus() {
        log.info("获取营业状态");
        Integer status = (Integer) redisTemplate.opsForValue().get(ShopStatusConstant.SHOP_STATUS);
        if (status != null) {
            log.info("当前营业状态为{}", status.equals(1) ? "营业中" : "打烊中");
        }
        return Result.success(status);
    }

}
